﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using Southridge.Data;
using Microsoft.Windows.Controls.Primitives;
using System.Windows;

namespace Southridge.View
{
    
    public class ListingToOneLineAddressConverter : IValueConverter
    {
         
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Listing listing = (value as Listing);


#if SQLCE 
            if (listing != null && listing.Address != null )
            {
                string s = listing.Address.ToOneLine();
                return s;
            }
#else 
            if ( listing != null ) 
            {
                  string s=  
                      listing.Address1 + ", " +
                    listing.City + ", " +
                    listing.State + " " +
                    listing.ZipCode;
                  return s; 
            } 
#endif 
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // not implemented
            return null;
        }

        #endregion
    }

    public class BoolToOpacityConverter : IValueConverter
    {

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                bool b = (bool)value;
                if (b) return 1; else return 0;
            }
            catch
            {
                return 1;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }


    public class BoolToVisibilityConverter : IValueConverter
    {

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                bool b = (bool)value;
                if (b) return Visibility.Visible; else return Visibility.Hidden;
            }
            catch
            {
                return Visibility.Hidden;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }



    public class ObjectToTypeName : IValueConverter
    {

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null)
            {
                return value.GetType().Name;
            }
            else
            {
                return null;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }



    public class ProfileToTitleConverter : IMultiValueConverter
    {


         
        public object Convert(object []values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            if (values.Length > 1 &&
                    values[0] != null && values[1] != null  && 
                    values[0] != DependencyProperty.UnsetValue && 
                    values[1] != DependencyProperty.UnsetValue )
            {
                if ( !string.IsNullOrEmpty(values[0] as string)&&
                     !string.IsNullOrEmpty(values[1] as string ))
                {
                    return string.Format ( "Profile for {0} {1} " , values[0], values[1] ) ; 
                } 
            } 
            return ""; 
        }


        public object[]  ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
 	        throw new NotImplementedException();
        }
 
    }   
}